#!/bin/bash
# 创建集群

# k3d cluster create dev  -p "443:443@loadbalancer" -p "80:80@loadbalancer" --servers 1 --agents 2 -i k3d --k3s-arg "--disable=traefik@server:0"
# export version="v1.24.0-rc1-k3s1-amd64"

# 查看k3s最新版本
# export k3s_version=$(curl -s https://api.github.com/repos/k3s-io/k3s/releases/latest | jq -r .tag_name)
# export k3s_version=$(curl -s https://api.github.com/repos/k3s-io/k3s/tags | jq -r '.[0].name')
# echo $k3s_version

# export image="$image_name:$version"
export chainguard="cgr.dev/chainguard/k3s" #安全无漏洞的镜像版本
export k3s="rancher/k3s"
export tag='v1.34.2-k3s1-amd64' #自定义版本
export spinkube="ghcr.io/spinkube/containerd-shim-spin/k3d:v0.19.0"
# -------安装参数--------
export servers="1"
export agents="2"
export registry_config="registries.yaml" #/etc/rancher/k3s/registries.yaml
export registry_use="k3d-registry:5000"
export cluster_name="dev"
export port="6550"

# 指定镜像版本 --image rancher/k3s:v1.23.4-k3s1 不指定用默认 --image $image #  -p "443:443@loadbalancer" -p "80:80@loadbalancer" \
k3d cluster create $cluster_name --api-port $port --verbose \
	-p "443:443@loadbalancer" -p "80:80@loadbalancer" -p "53:53@loadbalancer" \
	--servers $servers --agents $agents \
	--k3s-arg "--disable=traefik@server:*" \
	--registry-config $registry_config \
	--image $k3s:$tag

# --image $k3s:$tag

# --image $spinkube

# --image $chainguard

# --image $k3s:$tag
# --image $wasm_k3s
# --image $chainguard
# --registry-use $registry_use \

# --image $wasm_cluster
# #用contour做 ingress
# k3d cluster create $cluster_name --api-port $port --verbose \
#     -p "443:8443@loadbalancer" -p "80:8080@loadbalancer" \
#     --servers $servers --agents $agents \
#     --k3s-arg "--disable=traefik@server:*" \
#     --registry-config $registry_config --image $chainguard

# k3d cluster create demo --api-port 6443  -p "8443:443@loadbalancer" -p "8080:80@loadbalancer" --image $image  --servers 1 --agents 2 --k3s-arg "--disable=traefik@server:*" --verbose  --registry-config /home/youling/k3d/install/sh/k3d/registries.yaml

# 更改数据平面label
kubectl label node k3d-dev-agent-0 node-role.kubernetes.io/worker=worker
kubectl label node k3d-dev-agent-1 node-role.kubernetes.io/worker=worker
kubectl taint nodes k3d-dev-server-0 key1=value1:NoExecute
# 设置污点
# kubectl taint nodes node1 key1=value1:NoSchedule  # pod不会被调度到这个节点
# kubectl taint nodes node1 key1=value1:NoExecute   # pod会被驱逐
# kubectl taint nodes node1 key2=value2:NoSchedule

# 输出kubeconfig
rm -rf /mnt/c/Users/Administrator/AppData/Roaming/Freelens/kubeconfigs/k3d-dev
export KUBECONFIG=$HOME/.kube/config
cat $HOME/.kube/config >/mnt/c/Users/Administrator/AppData/Roaming/Freelens/kubeconfigs/k3d-dev
